
import java.io.*;
class Commandes extends Runnable {
  Tracker _tracker;

  BufferedReader _in;

  String _strCommande = "";

  Thread _t;

  Commandes(Tracker tracker) {
    _tracker=tracker;
    _in = new BufferedReader(new InputStreamReader(System.in));
    _t = new Thread(this); 
    _t.start();
  }

  public void run() {
    try{
 
      while ((_strCommande=_in.readLine())!=null){
        if (_strCommande.equalsIgnoreCase("quit"))
          System.exit(0); 
        else if(_strCommande.equalsIgnoreCase("total")) {
          System.out.println("Nombre de connectes : "+_tracker.getNbClients());
          System.out.println("--------");
        }
        else if(_strCommande.equalsIgnoreCase("showbdd")) {
        	_tracker._bdd.printKey();
        	System.out.println("");
          }
        else if(_strCommande.equalsIgnoreCase("tabid")) {
        	System.out.println("Contenu de tabId : ");
        	for (int j = 0; j < _tracker._tabId.size(); j++){
        		if(_tracker._tabId.elementAt(j)!=null){
        			System.out.print(_tracker._tabId.elementAt(j)+" ");
        		}	
        	}System.out.println("");
        	System.out.println("--------");
        }
        else{
          System.out.println("Cette commande n'est pas supportee");
          System.out.println("Quitter : \"quit\"");
          System.out.println("Nombre de connectes : \"total\"");
          System.out.println("--------");
        }
        System.out.flush();
      }
    }
    catch (IOException e) {}
  }

}
